package com.caption.jdk.stream;

import java.util.*;
import java.util.stream.Stream;

/**
 * Stream 获取方式
 * 1.通过集合方式
 * 2.如果是数组可以通过stream.of方式获取
 */
public class TestStream01 {

    public static void main(String[] args) {
        //通过list方式获取
        List<String> list = Arrays.asList("张三", "张三丰", "李四", "王五八点");
        list.stream()
                .filter(st -> st.startsWith("张")).filter(st -> st.length() == 3).forEach(s -> System.out.println(s));
        //map本身没有stream接口,需要获取 keySet 或者是ValueSet方式
        Map<String,Object> map=new HashMap<>();
        map.put("zhangsan",20);
        map.put("lisi",30);
        map.put("wangwu",25);
        map.keySet().stream().filter(s->s.startsWith("zhang")).forEach(s-> System.out.println(s));
        map.values().stream().filter(age-> (Integer)age>25).forEach(s-> System.out.println(s));
        map.entrySet().stream().filter(r-> r.getKey().startsWith("li")).forEach(e-> System.out.println(e.getKey()));

        //数组通过Stream.of()方式获取stream
        String[] arr =  { "a","b","c"};
        Stream.of(arr).filter(s->s.startsWith("a")).forEach(s -> System.out.println(s));

    }
}
